package cn.juque.jdfsystem.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.juque.common.base.BaseRequestVO;
import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.base.PageInfo;
import cn.juque.common.constants.MessageEnum;
import cn.juque.jdfsystem.entity.LogInfo;
import cn.juque.jdfsystem.service.ILogInfoService;
import cn.juque.jdfsystem.vo.loginfo.LogInfoListVO;
import cn.juque.jdfsystem.vo.loginfo.LogInfoSearchVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>LogInfoController</li>
 * </ul>
 * @date 2023-01-10 18:41:39
 **/
@Slf4j
@Controller
@RequestMapping("/jdf/log")
public class LogInfoController extends BaseController {

    @Resource
    private ILogInfoService logInfoService;

    /**
     * 查询
     *
     * @param request BaseRequestVO
     * @return BaseResponseVO
     */
    @PostMapping(value = "/list")
    @ResponseBody
    public BaseResponseVO<List<LogInfoListVO>> list(@RequestBody BaseRequestVO<LogInfoSearchVO> request) {
        LogInfoSearchVO searchVO = super.validatorUtil.checkNotNull(request);
        PageInfo pageInfo = request.getPageInfo();
        super.validatorUtil.checkPageInfo(pageInfo);
        LogInfo logInfo = new LogInfo();
        BeanUtil.copyProperties(searchVO, logInfo);
        List<LogInfo> list = this.logInfoService.listInfoWithPage(pageInfo, logInfo);
        List<LogInfoListVO> voList = BeanUtil.copyToList(list, LogInfoListVO.class);
        return new BaseResponseVO<>(MessageEnum.OK, voList, pageInfo);
    }
}
